<%-- 
    Document   : ljxm
    Created on : 2016-7-18, 14:59:50
    Author     : cxhd
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@include file="../../link.jsp" %>
<!--        <link href="../../css/bootstrap-paper.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="${base}/js/jquery.ztree.all.js"></script>
        <script type="text/javascript" src="${base}/js/bootstrap.min.js"></script>-->
        <title>临检项目以及参数设置</title>
    </head>
    <body ng-app="ljxm" ng-controller="sz">
        <style>
            body{background-color: #ffffff}
            tr>th{ padding: 1px}
            input{font-weight:bold}
            .error{font-size: 1px; color: red}
        </style>
        <div>
            <div class="col w-lg bg-light dk b-r bg-auto" id="aside" style="background-color: #ffffff;width: 40%">
                <div class="wrapper bg b-b" style="height: 48px;">
                    <!--<button class="btn btn-sm btn-success pull-right" ui-toggle-class="timeline-center" target=".timeline">Center</button>-->
                    <h4 class="m-n font-thin">项目浏览</h4>

                    <div class="wrapper" >
                        <div style="height:20px">
                            <input ng-model="searchContent"  placeholder="项目名/项目id" style="width:320px; float: left;margin-left: 20px" class="form-control input-sm" ng-change="getListTes()" />
                            <!--                        <button ng-click="getListTes()" style="float: left" class="btn btn-success btn-sm"><span class="fa fa-search"></span>&nbsp;&nbsp;搜索</button>-->
                        </div>
                    </div>
                    <form class="ng-pristine ng-valid">
                        <table  class="table table-striped table-bordered  table-hover" style="width:100%"  >
                            <tr>
                                <th class="table-id">项目id</th>
                                <th class="table-title">项目全名</th>
                                <th class="table-type">样本类型</th>
                                <th class="table-author">单位</th>
                                <th class="table-type">价格</th>
                            </tr>
                            <tr  ng-repeat="tes in tess" ng-click="getTesInfo(tes)">
                                <td>{{tes.TESTID}}</td>
                                <td>{{tes.CHINESENAME}}</td>
                                <td>{{tes.SAMPLEDESCRIBE1}}</td>
                                <td>{{tes.UNIT1}}</td>
                                <td>{{tes.PRICE}}</td>
                            </tr>
                        </table>
                    </form>

                    <footer class="panel-heading">
                        <div class="row">
                            <div style="text-align: center" >                
                                <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                            </div>
                        </div>
                    </footer>

                </div>
            </div>
            <div style="position: fixed;left:40%;top: 0px;bottom: 0px; width:60%;margin-bottom: 20px;overflow: auto">
                <form name="formXm" id="profile" >
                    <div>
                        <button class="btn m-b-xs btn-sm btn-success btn-addon" ng-disabled="formXm.$invalid" ng-click="saveTes()"><i class="fa fa-save"></i>保存</button>
                        <button class="btn m-b-xs btn-sm btn-danger btn-addon" ng-click="deleteTes()"><i class="fa fa-bolt"></i>删除</button>
                        <button class="btn m-b-xs btn-sm btn-primary btn-addon" ng-click="cancelEvent()"><i class="fa fa-cab"></i>取消</button>
                        <button class="btn m-b-xs btn-sm btn-info btn-addon" ng-click="newTes()"><i class=" fa-recycle"></i>重置</button>
                        <!--<button class="btn m-b-xs btn-sm btn-info btn-addon" ng-click="addPrintOrd()"><i class="fa fa-print"></i>新增打印次序</button>-->
                        <!--<button class="btn m-b-xs btn-sm btn-info btn-addon" ng-click="saveRef()"><i class="fa fa-close"></i>新增参数</button>-->
                    </div>
                    <ul class="nav nav-tabs" role="tablist">
                        <li role="presentation" class="active"><a href="/demo/bootstrap3-plugin-tab.htm#home" aria-controls="home" role="tab" data-toggle="tab">基础信息</a></li>
                        <!--<li role="presentation"><a href="/demo/bootstrap3-plugin-tab.htm#profile" aria-controls="profile" role="tab" data-toggle="tab">通道号</a></li>-->
                        <!--    <li role="presentation"><a href="/demo/bootstrap3-plugin-tab.htm#messages" aria-controls="messages" role="tab" data-toggle="tab">仪器和科室</a></li>-->
                        <li role="presentation"><a href="/demo/bootstrap3-plugin-tab.htm#settings" aria-controls="settings" role="tab" data-toggle="tab">参考范围</a></li>
                        <li role="presentation" ><a href="/demo/bootstrap3-plugin-tab.htm#refencevalue" aria-controls="refencevalue" role="tab" data-toggle="tab">参考值</a></li>
                        <!--     <li role="presentation"><a href="/demo/bootstrap3-plugin-tab.htm#settings" aria-controls="czgc" role="tab" data-toggle="tab">操作规程</a></li>
                             <li role="presentation"><a href="/demo/bootstrap3-plugin-tab.htm#settings" aria-controls="jgts" role="tab" data-toggle="tab">警告提示</a></li>-->

                    </ul>

                    <div class="tab-content">
                        <div role="tabpanel" class="tab-pane active" id="home">

                            <table class="table table-striped table-bordered  table-hover" style="width:100%" >
                                <tr><td>项目ID：<input type="text" ng-model="tesI.TESTID" id="testid" name="testid" style="width: 100px" ng-minlength=1 ng-maxlength=20 required/>
                                        <div class="error" ng-show="formXm.testid.$dirty && formXm.testid.$invalid">
                                            <small class="error" ng-show="formXm.testid.$error.required">项目ID不能为空。</small>
                                            <small class="error" ng-show="formXm.testid.$error.minlength">项目ID长度不能小于3</small>
                                            <small class="error" ng-show="formXm.testid.$error.maxlength">项目ID长度不能大于10</small> 
                                        </div>
                                    </td>
                                    <td>项&nbsp;目&nbsp;名：<input type="text" ng-model="tesI.CHINESENAME" name="chinesename" style="width: 100px" ng-minlength=1 ng-maxlength=20 required/>
                                        <div class="error" ng-show="formXm.chinesename.$dirty && formXm.chinesename.$invalid">
                                            <small class="error" ng-show="formXm.chinesename.$error.required">项目名不能为空。</small>
                                            <small class="error" ng-show="formXm.chinesename.$error.minlength">项目名长度不能小于3</small>
                                            <small class="error" ng-show="formXm.chinesename.$error.maxlength">项目名长度不能大于10</small> 
                                        </div>
                                    </td> 
                                    <td>样本类型：
<!--                                        <input type="text" ng-model="SAMPLEDESCRIBE"/>
                                        {{tesI.SAMPLETYPE}}-->
                                        <select ng-model="tesI.SAMPLETYPE" ng-options="sam.PK as sam.SAMPLEDESCRIBE for sam in sams" style="width: 100px" ng-selected="sam.PK==tesI.SAMPLETYPE">
                                             </select>
<!--                                       <select  class="form-control" style="width: 100px;" ng-model="tesI.SAMPLETYPE">
                                                <option ng-repeat="sam in sams">{{sam.SAMPLEDESCRIBE}}</option>
                                            </select>  -->
                                       
                                    </td>
                                </tr>          
                                <tr><td>单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;位：
                                        <select ng-model="tesI.UNIT" ng-options=" unit.UNITNAME as unit.UNITNAME for unit  in units" ng-select="tesI.UNIT==unitUNITNAME">
                                            
                                        </select>                                    
                                    </td>
                                    <td>价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格：<input type="text" ng-model="tesI.PRICE" style="width: 100px"/></td> 
                                    <td><input type="checkbox" id="jj" ng-model="check" style="width: 50px"/>紧&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;急</td>
                                </tr>
                                <tr ><td>项目英文名：<input type="text" ng-model="tesI.ENGLISHNAME" style="width: 100px"/></td>
                                    <td>项目结果类型<select ng-model="tesI.REFCLASS" >
                                            <option value="1" >数值类型</option>
                                            <option value="2">阴阳类型</option>
                                            <option value="3">文字类型</option>
                                        </select>
                                    </td> 
                                    <td></td>
                                </tr>
                            </table>

                        </div>

                        <!--      <div role="tabpanel" class="tab-pane" id="profile">
                                  <table>
                                      <tr><td><input type="text"  ></td></tr>
                                  </table>
                                  <button>新增</button><button>删除</button>
                              </div>-->
                        <!--    <div role="tabpanel" class="tab-pane" id="messages">333</div>
                            <div role="tabpanel" class="tab-pane active" id="home">1111</div>-->
                        <div role="tabpanel" class="tab-pane" id="settings">
                            项目名称：<input type="text" ng-model="tesI.CHINESENAME" ><button ng-click="addRefs()" style="width:100px;">新增</button>
                            <div ng-repeat="ref in refs"> 
<!--                                <div>                                                                                                                                                                      
                                   样本类型： <select  class="form-control" style="width: 100px;" ng-model="ref.SAMPLETYPE">
                                                <option ng-repeat="sam2 in sams">{{sam2.SAMPLEDESCRIBE}}</option>
                                            </select>    
                                </div>-->
                                <table class="table table-striped table-bordered  table-hover" style="width:100%"  >
                                    <tr><td> 样本类型：</td><td colspan="4" >   <select ng-model="tesI.SAMPLETYPE" ng-options="sam.PK as sam.SAMPLEDESCRIBE for sam in sams" style="width: 100px" ng-selected="sam.PK==tesI.SAMPLETYPE">
                                             </select> </td>
<!--                                            <td ></td><td ></td><td ></td>-->
                                    </tr>
                                    <tr >

                                        <th class="table-id">参考年龄</th>
                                        <th class="table-title">参考性别</th>
                                        <th class="table-type">病理范围</th>
                                        <th class="table-author">参考低限</th>
                                        <th class="table-type">参考高限</th>
                                    </tr>
                                    <tr>  
                                        <td><input type="text" ng-model="ref.REFAGE" style="width:100px;text-align: center"> </td>
                                        <td>男</td>
                                        <td ><input type="text" value="双侧" readonly="true"  style="width:100px;text-align: center"></td>
                                        <td><input type="text" ng-model="ref.MREFLO0" style="width:100px;text-align: center"></td>
                                        <td><input type="text" ng-model="ref.MREFHI0" style="width:100px;text-align: center"></td>
                                    </tr>
                                    <tr>   
                                        <td><button ng-click="deleteRefs($index)" style="width:100px;">删除</button></td>
                                        <td>女</td>
                                        <td>结果有效位数：<select ng-model="ref.Decimalplace">
                                                <!--<option value="">保持原有位数</option>-->
                                                <option value="0">0位</option>
                                                <option value="1">1位</option>
                                                <option value="2">2位</option>
                                                <option value="3">3位</option>
                                                <option value="4">4位</option>
                                            </select></td>
                                        <td><input type="text" ng-model="ref.FREFLO0" style="width:100px;text-align: center"></td>
                                        <td><input type="text" ng-model="ref.FREFHI0" style="width:100px;text-align: center"></td>

                                    </tr>
                                </table>

                            </div>
                            <!--    <div role="tabpanel" class="tab-pane" id="lcyy">
                                    <textarea style="width:600px;height: 400px">
                                        
                                    </textarea>
                                </div>-->
                            <!--    <div role="tabpanel" class="tab-pane" id="czgc">333</div>
                                <div role="tabpanel" class="tab-pane" id="jgts">444</div>-->

                        </div>
                        <div role="tabpanel" class="tab-pane" id="refencevalue">
                             项目名称：<input type="text" ng-model="tesI.CHINESENAME" ><button ng-click="addRefVal()" style="width:100px;">新增</button>
                            <div ng-repeat="refval in refvals"> 
                            <table class="table table-striped table-bordered  table-hover" style="width:100%"  >
                                    <tr><td> 样本类型：</td><td colspan="4" >   <select ng-model="refval.SAMPLETYPEPK" ng-options="sam.PK as sam.SAMPLEDESCRIBE for sam in sams" style="width: 100px" ng-selected="sam.PK==refval.SAMPLETYPE">
                                             </select> </td>
<!--                                            <td ></td><td ></td><td ></td>-->
                                    </tr>
                                    <tr >

                                        <th class="table-id">参考年龄</th>
                                        <th class="table-title">参考性别</th>
                                        <th class="table-type">病理范围</th>
                                        <th class="table-author">参考值</th>
                                      
                                    </tr>
                                    <tr>  
                                        <td><input type="text" ng-model="refval.REFAGE" style="width:100px;text-align: center"> </td>
                                        <td>男</td>
                                        <td ><input type="text" value="双侧" readonly="true"  style="width:100px;text-align: center"></td>
                                        <td><input type="text" ng-model="refval.MREFVAL0" style="width:100px;text-align: center"></td>
                                      
                                    </tr>
                                    <tr>   
                                        <td><button ng-click="deleteRefVal()" style="width:100px;">删除</button></td>
                                        <td>女</td>
                                        <td>结果有效位数：<select ng-model="refval.DECIMALPLACE">
                                                <!--<option value="">保持原有位数</option>-->
                                                <option value="0">0位</option>
                                                <option value="1">1位</option>
                                                <option value="2">2位</option>
                                                <option value="3">3位</option>
                                                <option value="4">4位</option>
                                            </select></td>
                                        <td><input type="text" ng-model="refval.FREFVAL0" style="width:100px;text-align: center"></td>
                                       

                                    </tr>
                                </table>
                            </div>
                        </div>
                </form>
            </div>
        </div>
        <!--<input type="text" id="nl" style="width: 135px;"   data-am-datepicker="{format: 'yyyy-mm-dd', viewMode: 'years'}"  readonly required  class="read ">-->
        <!--<input type="text" class="am-form-field" placeholder="日历组件" data-am-datepicker readonly required />-->


    </body>

    <script>
        angular.module("ljxm", ['baseModule', 'ui.bootstrap'])
                .controller("sz", function ($scope, $http,base) {
                    $scope.tesI = {PK: ""};
                    $scope.refs = [{REFAGE: 0, MREFLO0: 0, MREFHI0: 0, FREFLO0: 0, FREFHI0: 0}];//参考范围
                    $scope.refvals=[{REFAGE: 0, MREFVAL0: 0, FREFVAL0: 0}];//参考值
                    var so = $scope;
                    $scope.data = {currentPage: 1};
                    so.setPage = function (pageNo) {
                        $scope.data.currentPage = pageNo;
                    };
                    so.pageChanged = function () {
                        $scope.getListTes();
                    };
                    so.data.maxSize = 4;
                    so.data.bigTotalItems = 20;
                    so.data.bigCurrentPage = 1;
                    so.data.pageSize = 10;


                    $scope.searchContent = "";
                    $scope.getListTes = function () {
                        base.post("lisTes/getLisTes", {pageSize: so.data.pageSize, currentPage: so.data.currentPage, searchContent: $scope.searchContent}).get( function (data) { //参数 分页参数
                            console.log(data);
                            if (data) {
                                $scope.tess = data.list;
                                so.data.bigTotalItems = data.totalRow;
//                                $scope.$apply();

                            }
                        })
                    }
                    $scope.getListTes();
                    $scope.getTesInfo = function (info) {//表的行单机事件
                        $scope.tesI = info;
                        if ($scope.tesI.PK != "") {
                            $("#testid").prop('readonly', true);
                        } else {
                            $("#testid").prop('readonly', false);
                        }
                        if (info.EMERGENCY != 0) {
                            $("#jj").prop('checked', true);
                        } else {
                            $("#jj").prop('checked', false);

                        }
                        $scope.getLisRefe();
                        $scope.getLisRefVals();
                    }
                    $scope.getSam = function () {//获取样本类型
                        base.post("device/getLisSam").get(function (data) {
                             console.log(data);
                            if (data) {
                                $scope.sams = data;
                            }
                        })
                    }
                    $scope.getSam();
                    $scope.deleteTes = function () {
                        var gnl = confirm("你真的确定要删除吗?"); //友好提示
                        if (gnl == true) {
                            base.post("lisTes/deleteLisTes", {TESTID: $scope.tesI.TESTID}).get( function (data) {
                                if (data == 'true') {
                                    alert("删除成功", 1000);
                                    $scope.getListTes();
//                                    $scope.$apply();
                                }
                            })
                        } else {
                            return;
                        }
                    }
                    $scope.cancelEvent = function () {
                        $scope.newTes();

                    }
                    $scope.newTes = function () {//新项目
                        location = location;//刷新页面
//                        $scope.tesI = {PK: "", TESTID: "", CHINESENAME: ""};
//                        $("#testid").prop('readonly', false);
//                        $("#jj").prop('checked', false);
//                        $scope.refs = [{REFAGE: 0, MREFLO0: 0, MREFHI0: 0, FREFLO0: 0, FREFHI0: 0}];
                    }
                    $scope.saveTes = function () {//保存项目或保存修改
                        base.post("lisTes/getTestIdRep", {TESTID: $scope.tesI.TESTID, PK: $scope.tesI.PK}).get( function (data) {
                            if (data == 'true') {
                                alert("项目ID在数据库中已存在", 1000);
                                return;
                            }
//                $.post("lisTes/getLisTesReP",{CHINESENAME:$scope.tesI.CHINESENAME,PK:$scope.tesI.PK},function(data){
//                     if(data=='true'){
//                         alert("项目名称在数据库中已存在",1000);
//                         return;
//                     }

                            if ($scope.check) {
                                $scope.tesI.EMERGENCY = 1;
                            } else {
                                $scope.tesI.EMERGENCY = 0;
                            }

                            var test = JSON.stringify($scope.tesI);
                           
                            if ($scope.tesI.PK == "" || $scope.tesI.PK == null) { //新增 
//                    $scope.ref={REFAGE:0,MREFLO0:0,MREFHI0:0,FREFLO0:0,FREFHI0:0};
                                var tefs = JSON.stringify($scope.refs);
                                var refvals=JSON.stringify($scope.refvals);
                                base.post("lisTes/saveLisTes", {TEST: test, TEF: tefs,REFVALS:refvals}).get( function (data) {
                                    if (data == 'true') {
                                        $scope.getListTes();
                                        alert("新增成功！", 1000);
                                    }
                                })
                            } else {// 修改
                                var tefs = JSON.stringify($scope.refs);
                                var refvals=JSON.stringify($scope.refvals);
                                base.post("lisTes/updateTes", {TEST: test, TEF: tefs,REFVALS:refvals}).get( function (data) {
                                    if (data == 'true') {
                                        $scope.getListTes();
                                        alert("修改成功！", 1000);
                                    }
                                })
                            }
//              }) 
                        })
                    }
                    $scope.getLisRefe = function () {

                        base.post("lisTes/getLisRefe", {TESTID: $scope.tesI.TESTID}).get( function (data) { //参数 项目id
                            if (data) {
                                $scope.refs = data;
                                if ($scope.refs.length == 0) {//用于没有参数数据的添加
                                    $scope.refs = [{REFAGE: 0, MREFLO0: 0, MREFHI0: 0, FREFLO0: 0, FREFHI0: 0}];
                                }
//                                $scope.$apply();
                            }

                        })
                    }
                    $scope.getLisRefVals = function () {

                        base.post("lisTes/getLisRerence", {TESTID: $scope.tesI.TESTID}).get( function (data) { //参数 项目id
                            if (data) {
                                $scope.refvals = data;
                                if ($scope.refvals.length == 0) {//用于没有参数数据的添加
                                    $scope.refvals = [{REFAGE: 0, MREFVAL0: 0, FREFVAL0: 0}];
                                }
//                                $scope.$apply();
                            }

                        })
                    }

//                    $scope.saveRef = function () {
//                        base.post("lisTes/addRef",{}).get( function (data) {
//                            if (data) {
//                                alert("新增成功");
//                            }
//                        })
//                    }
                    //参考范围的增减
                    $scope.addRefs = function () {
                        $scope.newRef = {REFAGE: 0, MREFLO0: 0, MREFHI0: 0, FREFLO0: 0, FREFHI0: 0};
                        $scope.refs.push($scope.newRef);
                    }
                    $scope.deleteRefs = function (tmp) {
                        $scope.refs.splice(tmp, 1);
                    }
                    //参考值得增减
                    $scope.addRefVal = function () {
                        $scope.newRefVal = {REFAGE: 0, MREFVAL0: 0, FREFVAL0: 0};
                        $scope.refvals.push($scope.newRefVal);
                    }
                    $scope.deleteRefVal = function (tmp) {
                        $scope.refvals.splice(tmp, 1);
                    }
//            $scope.addPrintOrd=function(){
//                $.post("lisTes/addPrindOrd",function(data){
//                    if(data){
//                        alert("新增成功");
//                    }
//                })
//            }
               $scope.getUnit=function(){
                   base.post("lisTes/getUnit").get(function(data){
                      if(data){
                          $scope.units=data;
                      } 
                   })
               }
               $scope.getUnit();
                })

    </script>
</html>
